package com.yzy.soft.system.freemarker.template;


import com.yzy.soft.system.freemarker.*;
import com.yzy.soft.system.freemarker.database.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class TemplateController extends TemplateKernel {
    private final static Logger logger= LoggerFactory.getLogger(TemplateDao.class);

    @Override
    public File generateFileType(FileInfo fileInfo, Table table, DBInfo dbInfo) throws Exception {
        JavaFileController javaFile=((JavaFile) fileInfo).getJavaFileController();
//        final String suffix = "Controller";
        final String templateName = "Controller.ftl";
        File file = new File(fileInfo.getDiskPath());
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("package_name", javaFile.getPackageName());
            dataMap.put("table_annotation", javaFile.getAnnotation());
            dataMap.put("class_requestMapping", javaFile.getRequestMapping());
            dataMap.put("table_name", javaFile.getFilename());
            dataMap.put("project_name", "");
            dataMap.put("idType", javaFile.getIdType());
            String path = fileInfo.getDiskPath() +javaFile.getFilename()+ javaFile.getSuffix();
        logger.info("controller path:"+path);
            File controllerFile = new File(path);
            generateFileByTemplate(templateName, controllerFile,fileInfo, dataMap);
//       super.fileList.add(controllerFile);
            return controllerFile;
    }

}
